package com.leetcode.LC_MED;

public class LC104 {
    int maxDeep = 0;

    public int maxDepth(TreeNode root) {
        if (root == null) {
            return 0;
        }

        toDepth(root, 0);
        return maxDeep;
    }

    private void toDepth(TreeNode root, int deep) {
        if (root == null) {
            maxDeep = Math.max(maxDeep, deep);
        } else {
            toDepth(root.left, deep + 1);
            toDepth(root.right, deep + 1);
        }
    }
    //官方解题
    public int maxDepth2(TreeNode root) {
        if (root == null) {
            return 0;
        } else {
            int leftHeight = maxDepth2(root.left);
            int rightHeight = maxDepth2(root.right);
            return Math.max(leftHeight, rightHeight) + 1;
        }
    }


}
